﻿using EasyI18n.Api.Infrastructure.DataPersistence.MongoDb;
using EasyI18n.Api.Infrastructure.DataPersistence.MongoDb.Entities;
using EasyI18n.Api.Primary.Bases;
using EasyI18n.Api.Primary.Contracts.Bases;
using EasyI18n.Api.Primary.Contracts.LanguageDictContracts;
using FluentValidation;
using Mediator.Net.Context;

namespace EasyI18n.Api.Realization.Handlers.LanguageDictHandlers;

public class CreateLanguageDictHandler(
    ICurrentSingle<SystemUser> currentUser,
    IDocumentAccessor<LanguageDict> languageDictDocs) : ICreateLanguageDictContract
{
    public async Task Handle(IReceiveContext<CreateLanguageDictCommand> context, CancellationToken cancellationToken)
    {
        
    }

    public void Validate(ContractValidator<CreateLanguageDictCommand> validator)
    {
        validator.RuleFor(e => e.ProjectId)
            .NotEmpty()
            .WithMessage("请选择一个项目");

        validator.RuleFor(e => e.WordId)
            .NotEmpty()
            .WithMessage("WordId不能为空");

        validator.RuleFor(e => e.LanguageWords)
            .Must(e => e is { Count: > 0 })
            .WithMessage("至少添加一个词");
    }

    public void Test(TestContext<CreateLanguageDictCommand> context)
    {
    }
}